#define _CRT_SECURE_NO_WARNINGS 1


#include<vector>
#include<iostream>

using namespace std;

int main()
{
	int n = 0;
	while (cin >> n)
	{
		vector<int> v(n);
		int count = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> v[i];
		}
		for (int i = 1; i < n - 1; i++)
		{
			if ((v[i] > v[i - 1] && v[i] < v[i + 1]) || (v[i] < v[i - 1] && v[i] > v[i + 1]))
			{
				count++;
			}
		}
		cout << count << endl;
	}

	return 0;
}